package com.wechat.server.mp.controller;


import com.wechat.server.mp.util.CommonConstant;
import com.wechat.server.mp.util.R;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author andy
 * @date 2016/12/18
 */
@RequestMapping("/sign")
@RestController
@RequiredArgsConstructor
@Slf4j
public class SignController {
    private final WxMpServiceImpl wxMpService;

    /**
     * 构建js-sdk所需配置
     *
     * @param url
     * @return
     */
    @RequestMapping(value = "/url", method = RequestMethod.GET)
    public R getSign(@RequestParam String url) throws WxErrorException {

            return R.ok().put("data", wxMpService.createJsapiSignature(url));

    }

    /**
     * 根据openId获取用户信息
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/getUserInfo", method = RequestMethod.GET)
    public R getUserInfo(@RequestParam String id) throws WxErrorException {

        return R.ok().put("data", wxMpService.getUserService().userInfo(id));

    }
}
